package com.nsoft.remotemedia.utils;

import java.util.List;

import com.nsoft.remotemedia.R;
import com.nsoft.remotemedia.objects.VideoItem;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MostPopularListAdapter extends ArrayAdapter<VideoItem>{
	private final Context context;
	private List<VideoItem> videoList;
	
	public MostPopularListAdapter(Context ctx,
						List<VideoItem> list){
		super(ctx,R.layout.layout_list_item,list);
		this.context=ctx;
		this.videoList=list;
	}
	
	@SuppressLint("UseValueOf")
	@Override
	public View getView(int pos, View convertView, 
								ViewGroup parent){
		LayoutInflater inflater=(LayoutInflater)context
				.getSystemService(
					Context.LAYOUT_INFLATER_SERVICE);
		
		View itemView=inflater.inflate(
				R.layout.layout_list_item,parent,false);
		
		VideoItem videoItem=this.videoList.get(pos);
		
		ImageView thumb=(ImageView)itemView.
						findViewById(R.id.itemThumb);
		new ImageLoader(thumb,videoItem.getImageUrl()).execute();
		
		TextView duration=(TextView)itemView.
						findViewById(R.id.itemDuration);
		duration.setText(videoItem.getDurationStr());
		
		TextView title=(TextView)itemView.
					findViewById(R.id.itemTitle);
		title.setText(videoItem.getTitle());
		
		TextView summary=(TextView)itemView.
					findViewById(R.id.itemSummary);
		summary.setText(videoItem.getSummary());
		
		TextView author=(TextView)itemView.
					findViewById(R.id.itemAuthor);
		author.setText("by "+videoItem.getAuthor());
		
		TextView viewCount=(TextView)itemView.
					findViewById(R.id.itemVideoCount);
		viewCount.setText(videoItem.getViewCount()+" views");
	
		return itemView;
	}
}
